﻿using System;
using Gonte.Reflection;

namespace Gonte.Workflow.Tasks
{
    public class CreateObject
        : ITask
    {
        #region Overridables

        public TaskResult Execute(TaskContext context)
        {
            ExceptionThrower.ThrowWhenNullOrEmpty("ObjectType", _objectType);

            TaskResult result = new TaskResult();
            Type type = System.Type.GetType(_objectType);
            result.Value = ObjectFactory.CreateObject(type);

            return result;
        }

        #endregion

        #region Properties

        public string ObjectType
        {
            get { return _objectType; }
            set { _objectType = value; }
        }

        #endregion

        #region Fields

        private string _objectType;

        #endregion
    }
}
